app:registClass("Transfer","app.world.views.Transfer")

app:registClass("StoryBranch","app.world.views.StoryBranch")

app:registInst(import(".models.WorldModel").new())

local UIController = require("app.world.controllers.UIController")
app:registInst(UIController.new({type="world", zOrder=SceneZOrder.desktopZOrder}))

NodeFactory = require("app.world.manager.NodeFactory").new()
NpcFactory = require("app.world.manager.NpcFactory").new()
TeamManager = require("app.world.manager.TeamManager").new()
MapManager = require("app.world.manager.MapManager").new()
DungeonManager = require("app.world.manager.DungeonManager").new()
NpcManager = require("app.world.manager.NpcManager").new()
DelayStack = require("app.world.manager.DelayStack").new()
BattleManager = require("app.world.manager.BattleManager").new()
FieldManager = require("app.world.manager.FieldManager").new()
TaskManager = require("app.world.manager.TaskManager").new()
StoryManager = require("app.world.manager.StoryManager").new()
ScriptManager = require("app.world.manager.ScriptManager").new()
AchievementManager = require("app.system.achievement.AchievementManager").new()
HistoryManager = require("app.system.history.HistoryManager").new()
RankingManager = require("app.system.ranking.RankingManager").new()
SecretManager = require("app.system.secret.SecretManager").new()


app.session:on("pb_map.S2C_MapUpdate",function(msg)
	FieldManager:onParseMapUpdate(msg)
end)

app.session:on("pb_map.S2C_EnterMap",function(msg)
	MapManager:onParseEnterMap(msg)
end)

--进入战斗数据广播
app.session:on("pb_map.S2C_EnterBattle",function(msg)
	dump("pb_map.S2C_EnterBattle")
	BattleManager:onParseEnterBattle(msg)
end)

app.session:on("battle2.S2C_SingleBattleStart",function(msg, rawData)
	BattleManager:onParseEnterSingleBattle(msg, rawData)
end)

app.session:on("battle2.S2C_QuickBattle", function(msg, rawData)
	BattleManager:onParseQuickBattleResult(msg, rawData)
end)

app.session:on("pb_arena.S2C_ArenaBattle",function(msg)
	BattleManager:onParseEnterArenaBattle(msg)
end)

app.session:on("pb_zombie.S2C_EnterZombieBattle",function(msg)
	BattleManager:onParseEnterBattle(msg, true)
end)


app.session:on("pb_melee.S2C_MeleeBattle",function(msg)
	BattleManager:onParseEnterArenaBattle(msg)
end)

app.session:on("pb_melee.S2C_MeleeInfo", function(msg)
	BattleManager:onParseEnterArenaBattlePre(msg)
end)

app.session:on("pb_throne.S2C_ThroneBattle", function(msg)
	BattleManager:onParseEnterArenaBattle(msg)
end)

--战斗结束广播
app.session:on("pb_map.S2C_BattleEnd",function(msg)
	BattleManager:onParseEndBattle(msg)
end)

--灰烬入侵战斗奖励广播
app.session:on("pb_graybattle.S2C_NotifyGrayBattleReward",function(msg)
	EM:notify("EVENT_GRAY_BATTLE_REWARD_NOTIFY", msg)
end)

app.session:on("action.S2C_UserGetFameExp",function(msg)
	DelayStack:push({name = "fame",exp = msg.exp,fameId = msg.fameId})
end)

app.session:on("pb_server.S2C_Announce",function(msg)
	app:dispatchCustomEvent("EVENT_ANNOUNCE_GET",{msg = msg})
end)


app.session:on("action.S2C_AssignCircle",function(msg)
	app:dispatchCustomEvent("EVENT_ASSIGN_CIRCLE",{msg = msg})
end)

app.session:on("pb_pick.S2C_UpdatePickPoints", function(msg)
	NpcManager:onUpdatePickPoint(msg.updatePoints)
end)

app.session:on("pb_dungeon.S2C_DungeonInfo",function(msg)
	DungeonManager:parseDungeonInfo(msg.dungeonInfo)
end)

app.session:on("pb_dungeon.S2C_EndDungeon",function(msg)
	DungeonManager:parseDungeonInfo(msg.dungeonInfo)
end)

app.session:on("pb_dungeon.S2C_EnterDungeon",function(msg)
	DungeonManager:parseEnterDungeon(msg)
end)

app.session:on("pb_dungeon.S2C_ResumeDungeon",function(msg)
	DungeonManager:parseResumeDungeon(msg)
end)

app.session:on("pb_newspaper.S2C_NewspaperNotify", function(msg)
	HistoryManager:parseNewspaperNotify(msg.Date)
end)

-- 跨服 工会战 战斗开始
app.session:on("pb_world.S2C_WorldGuildWarBattle", function(msg)
	BattleManager:onParseEnterArenaBattle(msg, true)
	print(os.date("%y/%m/%d, %H:%M:%S", app.session:getServerTime()))
	dump(msg, "S2C_WorldGuildWarBattle", 5)
	EM:notify(ViewEvent.CSGuildWar_EnterBattle)
end)
-- 跨服 工会战 轮空
app.session:on("pb_world.S2C_WorldGuildWarBattleSkip", function(msg)
	dump(msg, "S2C_WorldGuildWarBattleSkip", 5)
	EM:notify(ViewEvent.CSGuildWar_BattleEmpty)
end)